package sam.learn.biz.role.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sam.learn.biz.role.repo.entity.UserRoleRelation;
import sam.learn.biz.role.service.UserRoleRelationService;
import sam.learn.biz.user.repo.entity.UserInfo;
import sam.learn.biz.user.service.UserInfoService;
import sam.learn.framework.security.CurrentUser;

@RestController
@RequestMapping("/role")
public class UserRoleRelationController {

    @Autowired
    private UserRoleRelationService userRoleRelationService;

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private CurrentUser currentUser;

    @GetMapping("/queryUserRole")
    public UserRoleRelation getUserRoleBy() {
        User user = currentUser.currentUser();
        UserInfo userInfo = userInfoService.queryUserInfoBy(user.getUsername());
        return userRoleRelationService.getUserRoleRelationBy(userInfo.getUserId());
    }

}
